<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>网站详情·思通投研·让数据驱动投资价值!</title>
<link href="${pageContext.request.contextPath }/img/webLogoIcon.png" rel="shortcut icon">
<link href="${pageContext.request.contextPath }/css/bootstrap.min.css"
	rel="stylesheet">
<link href="${pageContext.request.contextPath }/css/font-awesome.css"
	rel="stylesheet">

<link href="${pageContext.request.contextPath }/css/animate.css"
	rel="stylesheet">
<link href="${pageContext.request.contextPath }/css/style.css"
	rel="stylesheet">
<link href="${pageContext.request.contextPath}/css/mypage.css" rel="stylesheet">
<link href="${pageContext.request.contextPath }/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
<!-- FooTable -->
<link href="${pageContext.request.contextPath }/css/footable.core.css"
	rel="stylesheet">
<link
	href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css"
	rel="stylesheet" />
<link href="${pageContext.request.contextPath }/css/datepicker3.css"
	rel="stylesheet">

<style>
.select2_demo_1 {
	float: left;
	width: 120px;
	display: inline;
	margin-left: 10px;
}

.form-control {
	display: inline;
}

.col-sm-3 {
	float: right;
	width: 560px;
}

.input-group {
	float: right;
	width: 240px;
	margin-left: 5px;
}

td {
	vertical-align: middle;
}
/* 策略sta */
.tactics{
	width: 100%;
	height: 80px;
	overflow:auto;
	padding:15px 0; 
	
}
.btgroup{
	width: 60%;
	display: flex;
	justify-content: space-between;
}
/* 策略end */
</style>

</head>

<body>

	<div id="wrapper">

		<nav class="navbar-default navbar-static-side" role="navigation">
			<%request.setAttribute("LEFT", "websitelist");%>
			<%@include file="left-factory.jsp"%>
		</nav>

		<div id="page-wrapper" class="gray-bg">
			<div class="row border-bottom">
				<jsp:include page="head-factory.jsp" flush="true" />
			</div>
			<div class="row wrapper border-bottom white-bg page-heading">
				<div class="col-lg-9">
					<h2>网站详情</h2>
					<ol class="breadcrumb">
	                	<li class="nav-main1">
	                		<a href="${pageContext.request.contextPath}/admin/tosystem_overview">主页</a>
	                	</li>
	                	<li class="nav-main2" >
                			<a id="navigation1" href="#" >站点资源</a>
                		</li>
                		<li class="nav-main2" >
                			<a id="navigation1" href="${pageContext.request.contextPath}/website/listwebsite" >网站列表</a>
                		</li>
	                	<li class="active">
	                		<a>网站详情</a>
	                	</li>
                	</ol>
				</div>
			</div>

			<div class="wrapper wrapper-content animated fadeInRight">
				<div class="row">
					<div class="col-lg-12">
						<div class="ibox float-e-margins">
							<div class="ibox-content">
								<div class="row" style="margin-top: 1%;">
									<div class="col-lg-12">
										<%-- <button class="btn btn-white pull-right" onclick="window.location.href = '${pageContext.request.contextPath}/website/toupdatewebsite?websiteId=${website.id}'" type="button" style="margin-left: 2%;">编辑</button> --%>
									</div>
									<div class="col-lg-12">
										<div class="m-b-md">
											<!-- <a> class="btn btn-white btn-sm pull-right" -->
											<h2 style="margin-left: 7%; float: left;"><img src="${website.website_ico}" width="30px;" style="vertical-align: bottom;">&nbsp;&nbsp;${website.website_name}</h2>
											<a style="float: left; margin: 1em 2em;color: inherit;" onclick="window.location.href = '${pageContext.request.contextPath}/website/toupdatewebsite?websiteId=${website.id}'"><i class="fa fa-edit"></i>&nbsp;编辑</a>
											<button class="btn btn-white pull-right" onclick="window.location.href = '${pageContext.request.contextPath}/website/listwebsite'" type="button" style="margin-left: 2%;">返回</button>
										</div>
									</div>
								</div>
								<div class="row" style="margin-top: 1%;">
									<div class="col-lg-5">
										<dl class="dl-horizontal">
											<dt style="font-size: 16px;">今日采集量:</dt>
											<dd style="font-size: 16px;">${todaynum}</dd>
											<dt style="font-size: 16px;">总计采集量:</dt>
											<dd style="font-size: 16px;">${totalnum}</dd>
											<dt style="font-size: 16px;">策略组:</dt>
											<dd style="font-size: 16px;">${fn:length(seed_config_utils)}</dd>
											<div class="tactics">
											<c:forEach var="config" items="${seed_config_utils }">  
												<button data="1" class="btn btn-primary" onclick="goedit(${config.id })">${config.seed_util_name }</button>
											</c:forEach>  
<!-- 												<button data="2" class="btn btn-primary" onclick="goedit(this)">策略二</button> -->
<!-- 												<button data="3" class="btn btn-primary" onclick="goedit(this)">策略三</button> -->
											</div>
											<div class="btgroup">
											<button class="btn btn-primary" onclick="window.location.href = '${pageContext.request.contextPath}/website_addtactics?websiteId=${website.id}&website_name=${website.website_name }'">添加策略</button>
											<button class="btn btn-primary">匹配策略</button>
											<c:if test="${website.capture_type == 0}">
												<button class="btn btn-primary" onclick="startMapping()">启动配置</button>
											</c:if>
											<c:if test="${website.capture_type == 1}">
												<button class="btn btn-primary">配置中。。。</button>
											</c:if>
											<c:if test="${website.capture_type == 2}">
												<button class="btn btn-primary" onclick="startMapping()">重新配置</button>
											</c:if>
											<button class="btn btn-primary" onclick="window.location.href = '${pageContext.request.contextPath}/website_splist?websiteId=${website.id}&website_name=${website.website_name }'">查看爬虫列表</button>
											</div>
										</dl>
									</div>
									<div class="col-lg-7" id="cluster_info">
										<dl class="dl-horizontal">
											<dt style="font-size: 16px;">网站地址:</dt>
											<dd style="font-size: 16px;">
												<a href="${website.website_url}" target="_blank" class="text-navy">${website.website_url}</a>
											</dd>
											<dt style="font-size: 16px;">创建时间:</dt>
											<c:set var="datestr" value="${website.create_date}"/>
											<c:set var="create_date" value="${fn:substring(datestr, 0, 19)}" />
											<dd style="font-size: 16px;">${create_date}</dd>
											<dt style="font-size: 16px;">备注信息:</dt>
											<dd style="font-size: 16px;">${website.website_remark}</dd>
										</dl>
									</div>
								</div>
							</div>
						</div>
						<div class="ibox float-e-margins">
							<div class="ibox-content">
								<!--<button class="btn btn-outline btn-primary dim" type="button">添加种子</button>-->
								<button class="btn btn-primary "
									onclick="window.location.href = '${pageContext.request.contextPath}/toaddseed?websiteId=${website.id}&website_name=${website.website_name }'"
									type="button">
									<i class="fa fa-plus"></i>&nbsp;添加种子
								</button>
								<table class="footable table table-stripped toggle-arrow-tiny"
									data-page-size="10" id="seed">
									<thead>
										<tr>

											<th style="width: 15%; text-align: center;">种子名称</th>
											<th style="width: 10%; text-align: center;">种子类型</th>
											<th style="width: 15%; text-align: center;">创建时间</th>
											<th style="width: 15%; text-align: center;">今日采集量</th>
											<th style="width: 15%; text-align: center;">总计采集量</th>
											<th style="width: 10%; text-align: center;">种子状态</th>
											<th style="width: 10%; text-align: center;">状态修改</th>
											<th style="width: 10%; text-align: center;">查看详情</th>
										</tr>
									</thead>
									<tbody>
										<c:forEach items="${list.list}" var="seed">
											<tr>
												<td style="text-align: center;">${seed.seed_name}</td>
												<c:if test="${seed.seed_type==1}">
													<td style="text-align: center;">HTML</td>
												</c:if>
												<c:if test="${seed.seed_type==2}">
													<td style="text-align: center;">JSON</td>
												</c:if>
												<c:if test="${seed.seed_type==3}">
													<td style="text-align: center;">JSONP</td>
												</c:if>
												<c:set var="seed_datestr" value="${seed.create_date}" />
												<c:set var="seed_create_date" value="${fn:substring(seed_datestr, 0, 19)}" />
												<td style="text-align: center;">${seed_create_date}</td>
												<td style="text-align: center;">${seed.todaynum}</td>
												<td style="text-align: center;">${seed.totalnum}</td>
												<c:if test="${seed.seed_status==1}">
													<td style="text-align: center;"><span id="typetitle${seed.id}" style="line-height: 2;" class="label label-primary">运行中</span></td>
													<td style="text-align: center;"><button id="typebutton${seed.id}" type="button"
															onclick="updateSeedflag(${seed.id},1)"
															class="btn-white btn btn-xs">关闭</button></td>
												</c:if>
												<c:if test="${seed.seed_status==0}">
													<td style="text-align: center;"><span id="typetitle${seed.id}" style="line-height: 2;" class="label label-danger">已关闭</span></td>
													<td style="text-align: center;"><button  id="typebutton${seed.id}"  type="button"
															onclick="updateSeedflag(${seed.id},0)"
															class="btn-white btn btn-xs">开启</button></td>
												</c:if>
												<td style="text-align: center;"><button type="button"
														onclick="window.location.href = '${pageContext.request.contextPath}/getseeddetail?seedid=${seed.id}&websiteId=${seed.website_id}'"
														class="btn-white btn btn-xs">种子详情</button></td>
											</tr>
										</c:forEach>
									</tbody>
									<tfoot>
										<tr>
											<td colspan="6">
												<c:if test="${list.pages>0}">
													<div class="box" id="box" style="float: right;"></div>
												</c:if>
											</td>
										</tr>
									</tfoot>
								</table>

							</div>
						</div>
					</div>
				</div>

			</div>
			<jsp:include page="footer.jsp" flush="true" />
		</div>


		<!-- Mainly scripts -->
		<script src="${pageContext.request.contextPath }/js/jquery-2.1.1.js"></script>
		<script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
		<script
			src="${pageContext.request.contextPath }/js/jquery.metisMenu.js"></script>
		<script
			src="${pageContext.request.contextPath }/js/jquery.slimscroll.min.js"></script>
		<script src="${pageContext.request.contextPath}/js/mypage.js"></script>

		<!-- Custom and plugin javascript -->
		<script src="${pageContext.request.contextPath }/js/inspinia.js"></script>
		<script src="${pageContext.request.contextPath }/js/pace.min.js"></script>

		<!-- Sweet alert -->
		<script src="${pageContext.request.contextPath }/js/plugins/sweetalert/sweetalert.min.js"></script>

		<!-- FooTable -->
		<script
			src="${pageContext.request.contextPath }/js/footable.all.min.js"></script>

		<!-- Page-Level Scripts -->
		<script>
        $(document).ready(function() {
            $('.footable').footable();
        });
        $(function(){
			paging(1,'${list.pages }','${list.pageNum }');
		});
        
        function paging(totalData,totalPage, pagenum) {
			$('#box').paging({
				initPageNo : pagenum, // 初始页码
				totalPages : totalPage, //总页数
				totalCount : '合计' + totalData + '条数据', // 条目总数
				slideSpeed : 600, // 缓动速度 单位毫秒
				jump : true, //是否支持跳转
				callback : function(page) {
					// 回调函数
				}
			});
		}
        
        function JumpToPage(pagenum) {
			window.location.href = "${pageContext.request.contextPath}/listseed?websiteId="+'${website.id}'+"&pageNum=" +pagenum;
		}
        function startMapping(){
        	swal({
                title: "确定启动配置？",
//              text: "Your will not be able to recover this imaginary file!",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: false,     
                closeOnCancel: true },
                function (isConfirm) {
                    if (isConfirm) {
                        $.ajax({
                            url:"${pageContext.request.contextPath}/startsMapping?websiteId=${website.id}",
                            type:"get",
                            success:function(res){
                                if (res.status == 200){
                                    swal("启动成功", "配置爬虫已开启", "success");
                                }
                            },
                            error:function(e){
                            	swal("启动失败", "配置爬虫未开启", "error");
                            }
                        })
                    } 
                });
        }
        function updateSeedflag(id,status) {
        	
        	swal({
                title: "确定修改?",
//              text: "Your will not be able to recover this imaginary file!",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: false,     
                closeOnCancel: true },
            function (isConfirm) {
                if (isConfirm) {
                    
                    $.ajax({
                        url:"${pageContext.request.contextPath}/updateSeedflag?status="+status+"&id="+id,
                        type:"get",
                        success:function(res){
                            if (res.status == 200){
                                /* $("#seed").empty();
                                $("#seed").load(location.href + " #seed"); */
                                if(status == 1){
                                $("#typetitle"+id).attr("class","label label-danger");
                                $("#typetitle"+id).html("已关闭");
                                $("#typebutton"+id).attr("onclick","updateSeedflag("+id+",0)");
                                $("#typebutton"+id).html("开启");
                                }
                                if(status == 0){
                                    $("#typetitle"+id).attr("class","label label-primary");
                                    $("#typetitle"+id).html("运行中");
                                    $("#typebutton"+id).attr("onclick","updateSeedflag("+id+",1)");
                                    $("#typebutton"+id).html("关闭");
                                    }
                                swal("修改成功", "状态已改变", "success");
                                
                            }
                        },
                        error:function(e){
                        	swal("修改失败", "状态未改变", "error");
                        }
                    })
                } 
            });
        	
        	
		}
        function goedit(id){
        	window.open("${pageContext.request.contextPath}/websitetactics/godit?id="+id+"&websiteId=${website.id}&website_name=${website.website_name }")
        }
	
        
      //跑马灯方法 
// 		 function init(){
// 			    //获取标题
// 			    var title=document.title;
// 			    //分割字符串--->字符数组
// 			    var arr=title.split("");
// 			    //删除第一个元素并返回该元素
// 			    var e=arr.shift();
// 			    //把一个对象添加到数组末尾
// 			    arr.push(e);
// 			    //把数组转换成字符串
// 			    var marquee=arr.join("");
// 			    //返回给浏览器
// 			    document.title=marquee;
// 			    //定时一直执行
// 			    window.setTimeout("init()",1000);
// 			}
// 			window.onload=init;
		 
    </script>

	<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
</body>

</html>
